package com.cskaoyan.wx.service;

import com.cskaoyan.bean.Brand;
import com.cskaoyan.bean.BrandExample;
import com.cskaoyan.mapper.BrandMapper;
import com.cskaoyan.wx.vo.BrandDetailVO;
import com.cskaoyan.wx.vo.WxBrandVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    BrandMapper brandMapper;

    /**
     * 品牌列表
     * @param page
     * @param size
     * @return
     */
    @Override
    public WxBrandVO getBrandList(Integer page, Integer size) {
        PageHelper.startPage(page,size);

        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        criteria.andDeletedNotEqualTo(true);
        List<Brand> brands = brandMapper.selectByExample(brandExample);

        PageInfo<Brand> brandPageInfo = new PageInfo<>(brands);
        long total = brandPageInfo.getTotal();

        WxBrandVO wxBrandVO = new WxBrandVO();
        wxBrandVO.setTotalPages((int) total);
        wxBrandVO.setBrandList(brands);
        return wxBrandVO;
    }

    /**
     * 品牌详情
     * @param id
     * @return
     */
    @Override
    public BrandDetailVO getBrandDetail(Integer id) {
        Brand brand = brandMapper.selectByPrimaryKey(id);
        BrandDetailVO brandDetailVO = new BrandDetailVO();
        brandDetailVO.setBrand(brand);
        return brandDetailVO;
    }
}
